<?php
namespace app\home\model;

use think\facade\Cookie;
use think\Model;

class User extends Model {
    public function index()
    {
        # code...

    }
    public function login($data)
    {
        # code...
        $validate = new \app\home\validate\User();
        if (!$validate->scene('login')->check($data)) {
            return $validate->getError();
        }
        $result = $this->where($data)->find();
        if ($result) {
            Cookie::set([
                'userid' => $result['id'],
                'username' => $result['username'],
                'tkoen' => $result['tkoen']
            ]);
            return 1;
        }else {
            return 0;
        }
    }
    public function getStausAttr($vua)//获取器 命名规则 get 表字段 Attr
    {
        # code...
        $get = [0 => '管理员', 1 => '正常', 2 => '禁用'];
        return $get[$vua];
    }
    public function getSexAttr($vua)//获取器 命名规则 get 表字段 Attr
    {
        # code...
        $get = ['男' => 'el-icon-female', '女' => 'el-icon-male'];
        return $get[$vua];
    }
}